package com.ct.main;

import com.ct.dao.Employee;
import com.ct.utils.Keyboard;

import java.security.Key;
import java.security.KeyStore;
import java.sql.Connection;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.SimpleTimeZone;

public class Main {
    public static Connection conn;
    public static Employee employee;

    public static void main(String[] args) throws SQLException {
        /**
         * 登录
         */
        allLogins();
    }

    public static void allLogins() {
        while(true){
            EmployeePanel employeePanel=new EmployeePanel();
            Menu.welcomePanelList();
            String s = Keyboard.keyCode();
            if (s.equals("1")){
                Employee employee = employeesLogin();
                if (employee.getPosition()==64){
                    employee.toString();
                    //管理员
                    employeePanel.adminPanel();
                }else if (employee.getPosition()==32){
                    //采购员
                    employeePanel.sellerPanel(employee);
                }else if (employee.getPosition()==16){
                    //收银员
                    int id = employee.getId();
                    employeePanel.cashierPanel(id,employee);
                }

            }else if (s.equals("2")){
                membersLogin();
                break;
            }else {
                continue;
            }
        }
    }

    public static Employee employeesLogin() {
        Employee e=null;
        while (true) {
            Employee login = Init.employeeLogin();
            e=login;
            if (login == null) {
                continue;
            }
            if (login.getIsEmployed() != 1) {
                System.out.println("已离职员工不得登录");
                Init.employeeLogin();
            }
            employee=login;
            System.out.println("欢迎！" + login.getEname());
            break;
        }
        return e;
    }

    public static void membersLogin() {
        while (true){
            System.out.println("1.查询积分");
            Menu.exit();
            String s = Keyboard.keyCode();
            if (s.equals("1")){
                Init.membershipLogin();
            }else if (s.equals("0")){
                allLogins();
                break;
            }
        }
    }

}
